<template>
  <div class="home">
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="审批人">
        <el-input v-model="formInline.user" placeholder="审批人"></el-input>
      </el-form-item>
      <el-form-item label="活动区域">
        <el-select v-model="formInline.region" placeholder="活动区域">
          <el-option label="区域一" value="shanghai"></el-option>
          <el-option label="区域二" value="beijing"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>
    
    <div class="res-btn">
      <el-button type="primary" icon="el-icon-plus" @click="dialogFormVisible = true">新增</el-button>
      <!--<el-button icon="el-icon-edit">修改</el-button>-->
      <!--<el-button icon="el-icon-delete">删除</el-button>-->
    </div>
    
    <div class="res-table">
      <el-table
          ref="multipleTable"
          :data="tableData"
          tooltip-effect="dark"
          style="width: 100%">
        <el-table-column
            prop="name"
            label="姓名"
            width="120">
        </el-table-column>
        <el-table-column
            prop="age"
            label="年龄"
            width="120">
        </el-table-column>
        <el-table-column
            prop="email"
            label="邮箱"
            show-overflow-tooltip>
        </el-table-column>
        <el-table-column
            fixed="right"
            label="操作"
            width="100">
          <template slot-scope="scope">
            <el-button type="text" size="small">编辑</el-button>
            <el-button @click="" type="text" size="small">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    
    <div class="res-page">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage4"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="100"
          layout="prev, pager, next, total, sizes, jumper"
          :total="400">
      </el-pagination>
    </div>
  
    <el-dialog title="新增" :visible.sync="dialogFormVisible">
      <el-form :model="addform">
        <el-form-item label="姓名" :label-width="formLabelWidth">
          <el-input v-model="addform.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="邮箱" :label-width="formLabelWidth">
          <el-input v-model="addform.email" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="年龄" :label-width="formLabelWidth">
          <el-input v-model="addform.age" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="addUser">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  // @ is an alias to /src

  export default {
    name: 'home',
    data() {
      return {
        formInline: {
          user: '',
          region: ''
        },
        tableData: [
          {
            name: '王小虎',
            age: '27',
            email: '123456789@qq.com',
            sex: '男'
          },
          {
            name: '王二丫',
            age: '26',
            email: '123456789@qq.com',
            sex: '女'
          }
        ],
        currentPage4: 4,
        multipleSelection: [],
        dialogFormVisible: false,
        addform: {
          name: '',
          email: '',
          age: ''
        },
        formLabelWidth: '80px'
      }
    },
    methods: {
      addUser() {
        this.$http.post('/user_add', this.addform)
          .then(res => {
            console.log(1)
            this.dialogFormVisible = false
          })
      },
      onSubmit() {
        console.log('submit!');
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
      }
    },
    mounted() {
      this.$http.get('/demo')
        .then(res => {
        
        })
    }
  }
</script>

<style lang="scss">
  .res-btn,
  .res-table,
  .res-page {
    margin-top: 20px;
  }
</style>